<?php
/*
 * SDOSocketConfig
 * 套接字配置文件
 * @author Wolfhead (Mei xueting)
 */

class SDOSocketConfig
{
    static protected $config;

    /*
     * 得到配置信息
     * @param $configName 配置项名称
     * @return Array | boolean
     */
    static public function getConfig($configName)
    {
        $curConfig = self::$config;
        $namespace = explode(".", $configName);
        
        for ($i = 0; $i != count($namespace); ++$i)
        {
            $currentName = strtolower($namespace[$i]);
            
            if (isset($curConfig[$currentName]))
            {
                if (isset($curConfig[$currentName]['host']))
                {
                    return $curConfig[$currentName];
                }
                $curConfig = $curConfig[$currentName];
            }
            else if (isset($curConfig["*"]))
            {
                if (isset($curConfig["*"]['host']))
                {
                    return $curConfig["*"];
                }
                $curConfig = $curConfig[$currentName];
            }
            else
            {
                return false;
            }
        }
        return false;
    }
    
    /*
     * 冲洗载入配置文件
     * @param $config 配置文件名
     * @return boolean
     */
    static public function reload($config)
    {
        self::$config = require $config;
        return true;
    }
}
/*
 * 载入默认配置
 */
SDOSocketConfig::reload('SDOSocketConfigDefault.php');
